//
// Created by tonystark on 16/3/28.
// Copyright (c) 2016 sewm. All rights reserved.
//

#import "YouDaoNavigationController.h"
#import "YouDaoTabBarController.h"
#import "LoginController.h"

@interface YouDaoNavigationController() <YouDaoTabBarViewControllerDelegate> {
    int m_lastTabIndex;
}
@end
@implementation YouDaoNavigationController {

}
+ (YouDaoNavigationController *)sharedInstance {
    static YouDaoNavigationController *_shareInstance;
    static dispatch_once_t onceT;
    dispatch_once(&onceT, ^{
        _shareInstance = [[YouDaoNavigationController alloc] init];
    });
    return _shareInstance;
}

// 在init中初始化，ios5会有bug
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationBarHidden = YES;
    m_lastTabIndex = -1;
    [self togLogin];
}

- (void)toggleTabBar {
    YouDaoTabBarController *controller = [[YouDaoTabBarController alloc] init];
    controller.delegate = self;
    self.viewControllers = @[controller];
}

- (void)togLogin {
    LoginController *controller = [LoginController new];
    self.viewControllers = @[controller];
}

- (void)youDaoSTabBarViewCOntroller:(YouDaoTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    int newTabIndex = tabBarController.selectedIndex;
    if (newTabIndex == m_lastTabIndex) {
        [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_TABCLICK object:@(newTabIndex)];
    } else {
        m_lastTabIndex = newTabIndex;
    }
}


@end